import type { SysPost } from "@/pages/system/post/entity";
import apiClient from "../../apiClient";

export interface PageListReq {
  //岗位编码
  postCode?: string;
  //岗位名称
  postName?: string;
  //当前页码
  page: number;
  //每页数量
  pageSize: number;
}

export interface PageListRes {
  //总记录数
  total: number;
  //数据列表
  records: SysPost[];
}

const pageList = (data: PageListReq): Promise<PageListRes> =>
  apiClient.post({
    url: "/system/post/pageList",
    data
});

const list = (): Promise<SysPost[]> =>
  apiClient.get({ url: "/system/post/list" });

const getInfo = (postId: React.Key): Promise<SysPost> =>
  apiClient.get({
    url: `/system/post/${postId}`
});

const add = (data: SysPost): Promise<SysPost> =>
  apiClient.post({
    url: "/system/post",
    data
});

const update = (data: SysPost): Promise<SysPost> =>
  apiClient.put({
    url: "/system/post",
    data
});

const remove = (postIds: React.Key[]): Promise<void> =>
  apiClient.delete({
    url: "/system/post",
    params: {
    ids: postIds.join(",")
  }
});

export const sysPostService = {
  pageList,
  list,
  getInfo,
  add,
  update,
  remove
};

export default sysPostService;